<template>
	<view class="MyData">
		<topbar-my-data></topbar-my-data>
		<view class="bgcolor"></view>
		<list-my-data :userImg="userImg" :listInfo="listInfo" @commitAvatar="commitAvatar"></list-my-data>
	</view>
</template>

<script>
	import {getAccountInfo,postAvatar} from "network/mine.js"
	
	import TopbarMyData from "./childMyData/TopbarMyData.vue"
	import ListMyData from "./childMyData/ListMyData.vue"
	
	export default{
		onLoad() {
			this._getAccountInfo()
			
		},
		components:{
			TopbarMyData,
			ListMyData,
		},
		data() {
			return {
				listInfo:{},
				userImg:""
			}
		},
		methods:{
			_getAccountInfo(){
				getAccountInfo().then(res=>{
					if(res.data.code == "B001"){
						this.listInfo = res.data.result[0]
						this.userImg = res.data.result[0].userImg
					}
				})
			},
			commitAvatar(e){
				postAvatar(e).then(res=>{
					if(res.data.code=="H001"){
						uni.showToast({
						    title: res.data.msg,
						    duration: 2000,
							icon:'none'
						})
						setTimeout(()=>{
							uni.navigateTo({
								url:"../myData/MyData"
							})
						},1000)
					}
				})
			}
		}
	}
</script>

<style scoped>
	.bgcolor{
		width: 100%;
		height: 200rpx;
		background-color: #0C34BA
	}
</style>
